#!/usr/bin/python
#
# LED daemon client
#
# Copyright (C) 2013 Anselm Lingnau <anselm@anselms.net>
#
# This program joins its command line arguments and passes
# them to the LED daemon.

import socket
import sys

HOST, PORT = "localhost", 33333

if len(sys.argv) > 1:
    data = " ".join(sys.argv[1:])
else:
    data = sys.stdin.read()

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

try:
    sock.connect((HOST, PORT))
    sock.sendall(data + "\n")
    received = sock.recv(1024)
except socket.error, e:
    print >>sys.stderr, "%s: socket error: %s" % (sys.argv[0], e)
    sys.exit(1)
finally:
    sock.close()

sys.exit(0 if received.strip() == "OK" else 1)
